
package com.yuan.model;

import com.yuan.prefence.FileConstants;
import com.yuan.prefence.UrlConstants;
import com.yuan.unit.FileUtils;
import com.yuan.unit.HttpUtils;
import com.yuan.unit.JsonUtils;

import android.content.Context;
import android.text.TextUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Users entity. @author MyEclipse Persistence Tools
 */
@SuppressWarnings("serial")
public class Users implements java.io.Serializable {

    private Integer id;
    private String username;
    private String pwd;
    private String realname;
    private String rights;
    private Integer pagesize;
    private String bumen;
    private String dataRight;
    private String firstpage;
    private String menu;
    private String 电话;

    private static Users sInstance;

    public static Users getInstance() {
        if (sInstance == null) {
            synchronized (Users.class) {
                if (sInstance == null) {
                    sInstance = new Users();
                }
            }
        }
        return sInstance;
    }

    /** default constructor */
    public Users() {
    }

    /** default constructor */
    public void setFromObject(Object mObject) {
        sInstance = (Users) mObject;
    }

    public void setFromMap(Map<?, ?> map) {
        try
        {
            this.id = (Integer) map.get("id");
            this.username = (String) map.get("username");
            this.pwd = (String) map.get("pwd");
            this.realname = (String) map.get("realname");
            this.rights = (String) map.get("rights");
            this.pagesize = (Integer) map.get("pagesize");
            this.bumen = (String) map.get("bumen");
            this.dataRight = (String) map.get("dataRight");
            this.firstpage = (String) map.get("firstpage");
            this.menu = (String) map.get("menu");
            this.电话 = (String) map.get("电话");
        } catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPwd() {
        return this.pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getRealname() {
        return this.realname;
    }

    public void setRealname(String realname) {
        this.realname = realname;
    }

    public String getRights() {
        return this.rights;
    }

    public void setRights(String rights) {
        this.rights = rights;
    }

    public Integer getPagesize() {
        return this.pagesize;
    }

    public void setPagesize(Integer pagesize) {
        this.pagesize = pagesize;
    }

    public String getBumen() {
        return this.bumen;
    }

    public void setBumen(String bumen) {
        this.bumen = bumen;
    }

    public String getDataRight() {
        return this.dataRight;
    }

    public void setDataRight(String dataRight) {
        this.dataRight = dataRight;
    }

    public String getFirstpage() {
        return this.firstpage;
    }

    public void setFirstpage(String firstpage) {
        this.firstpage = firstpage;
    }

    public String getMenu() {
        return this.menu;
    }

    public void setMenu(String menu) {
        this.menu = menu;
    }

    public String get电话() {
        return this.电话;
    }

    public void set电话(String 电话) {
        this.电话 = 电话;
    }

    /**
     * 用户登录具体实现
     * 
     * @param mContext
     * @return
     */
    public boolean login(Context mContext) {
        String str = null;
        if (TextUtils.isEmpty(username) || TextUtils.isEmpty(pwd))
        {
            return false;
        }
        String url = String.format(UrlConstants.LOGINURL, username, pwd);
        try {
            str = HttpUtils.getUrlContent(mContext, url, "UTF-8");
            HashMap<?, ?> mHashMap = JsonUtils.getMap0(str);
            FileUtils.Serializable2File(mHashMap, FileConstants.SERIALIZABLE_USERS);
            return true;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;
    }

    public boolean changepwd(Context mContext, String newpwd)
    {
        String str = null;
        if (TextUtils.isEmpty(username) || TextUtils.isEmpty(newpwd) || TextUtils.isEmpty(pwd))
        {
            return false;
        }
        String url = String.format(UrlConstants.CHANGEPWD, username, pwd, newpwd);
        try {
            str = HttpUtils.getUrlContent(mContext, url, "UTF-8");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return false;
        }
        if (TextUtils.isEmpty(str))
        {
            return false;
        }
        if (str.equals("修改成功"))
        {
            return true;
        }
        return false;
    }
}
